#include"HttpServer.hpp"
#include"Session.hpp"

void Login(HttpRequest &req, HttpResponse &resp)
{
    LOG(log_level::DEBUG)<<"进入登录模块"<<req.Path()<<","<<req.Args();
    std::string req_args = req.Args();
    

    // 1. 解析参数格式，得到要的参数
    // 2. 访问数据库，验证对应的用户是否是合法的用户，其他工作....
    // TODO
    // SessionManager m;
    // session_id = m.CreateSession(XXXXX);

    std::string body = req.GetContent("wwwroot/index.html");
    resp.SetCode(200);
    resp.SetBody(body);
    resp.SetHeader("Content-Type","text/html");
    resp.SetHeader("Content-Length",std::to_string(body.size()));
}
void Register(HttpRequest &req, HttpResponse &resp)
{
     LOG(log_level::DEBUG) << "进入注册模块" << req.Path() << "," << req.Args();
}

int main(int argc, char* argv[])
{
    if(argc!= 2){
        std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }
    std::unique_ptr<HttpServer> http_server= std::make_unique<HttpServer>(atoi(argv[1]));
    http_server->Resgister("/login",Login);
    http_server->Resgister("/register",Register);
    http_server->Start();
    return 0;
}